package 河北工业大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import 江苏大学.JSuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HBGu {
    public static void main(String[] args) throws IOException {
        HBGuBean hbGuBean = null;
        List<HBGuBean> hbGuBeans = new ArrayList<>();
        String url = "https://ee.hebut.edu.cn/szdw/jsml/index.html#main";
        Connection connect = Jsoup.connect(url);
        Document post = connect.get();
        Elements wlyTeacher = post.getElementsByClass("wly_teacher");
        for (Element element : wlyTeacher) {
            Elements div = element.getElementsByTag("div");
            for (Element element1 : div) {
                for (Element a : element1.getElementsByTag("a")) {
                    hbGuBean = new HBGuBean();
                    Connection connect1 = Jsoup.connect("https://ee.hebut.edu.cn/szdw/jsml/" + a.attr("href"));
                    Document document = connect1.get();
                    String text = document.getElementsByClass("newsXq_top").get(0).text();//姓名
                    hbGuBean.setT_name(text);
                    String text1 = document.getElementsByClass("substance newsXq_bom").get(0).text();//个人信息
                    if (text1.contains("教授")){
                        hbGuBean.setInfo(text1);
                    }else {
                        continue;
                    }
                    hbGuBeans.add(hbGuBean);
                }

            }
        }
        EasyExcel.write("src/HBGu.xlsx", HBGuBean.class).sheet("user").doWrite(hbGuBeans);
    }
}
